# from PySide6.QtWidgets import QApplication, QDialog, QVBoxLayout, QLabel, QPushButton

# class CustomDialog(QDialog):
#     def __init__(self, function, parent=None):
#         super().__init__(parent)
#         self.function = function
#         self.setWindowTitle("Custom Dialog")
        
#         layout = QVBoxLayout()
#         label = QLabel("Are you sure?")
#         layout.addWidget(label)
        
#         confirm_button = QPushButton("Confirm")
#         confirm_button.clicked.connect(self.confirm)
#         layout.addWidget(confirm_button)
        
#         cancel_button = QPushButton("Cancel")
#         cancel_button.clicked.connect(self.close)
#         layout.addWidget(cancel_button)
        
#         self.setLayout(layout)
    
#     def confirm(self):
#         self.function()
#         self.close()

# def my_function():
#     print("Function called!")

# app = QApplication([])
# dialog = CustomDialog(my_function)
# dialog.exec()

# for index,h_line in enumerate([1,2,3,4,5,6][::-1]):
#     print(f'{index}----{h_line}')
#     print([11,22,33,44,55,66][-(index+1)])




# import re
# def hasChinese(file_lines):
#     """
#     找出中文的位置
#     """
#     chinese_pos = []
#     for index,line in enumerate(file_lines):
#         pattern = re.compile(r'[\u4e00-\u9fa5]')
#         match = pattern.search(line)
#         if match is not None:
#             chinese_pos.append(index)
            
#     return chinese_pos

# file_lines = ['wedhwrfgwet','whr完全融合为ioiooi','wedhwrfgwet','wedhwrfgwet','whr完全融合为ioiooi','wedhwrfgwet','whr完全融合为ioiooi','whr完全融合为ioiooi']
# chinese_pos = hasChinese(file_lines)
# print(chinese_pos)


# import win32com.client

# def get_visio_data(file_path):
#     visio_app = win32com.client.Dispatch("Visio.Application")
#     visio_doc = visio_app.Documents.Open(file_path)
#     visio_page = visio_doc.Pages.Item(1)  # 获取第一个页面

#     shapes = visio_page.Shapes
#     data_stream = []

#     for shape in shapes:
#         if shape.CellExists("Prop.Data") and shape.CellExists("Prop.Label"):
#             data = {
#                 "data": shape.Cells("Prop.Data").Formula,
#                 "label": shape.Cells("Prop.Label").Formula
#             }
#             data_stream.append(data)

#     visio_doc.Close()
#     visio_app.Quit()

#     return data_stream

# # 示例用法
# file_path = "D:\python_tool_list\source_data\DE设计平台需求_20210901.vsd"
# data_stream = get_visio_data(file_path)
# for data in data_stream:
#     print(data)


# import sys
# from PySide6.QtWidgets import QApplication, QGraphicsView, QGraphicsScene, QGraphicsPolygonItem
# from PySide6.QtCore import Qt, QPointF

# class RadarChart(QGraphicsView):
#     def __init__(self):
#         super().__init__()
#         scene = QGraphicsScene(self)
#         self.setScene(scene)

#         # 定义雷达图的数据点
#         data_points = [(0, 80), (45, 90), (90, 70), (135, 60), (180, 85), (225, 50), (270, 75)]

#         # 创建多边形项
#         polygon_item = QGraphicsPolygonItem()
#         polygon = [QPointF(100 * 0.5 * 0.01 * x * 2, -100 * 0.5 * 0.01 * y) for x, y in data_points]
#         polygon_item.setPolygon(polygon)

#         # 将多边形项添加到场景中
#         scene.addItem(polygon_item)

#     def mouseMoveEvent(self, event):
#         # 获取鼠标移动的位置
#         pos = self.mapToScene(event.pos())

#         # 检查鼠标位置是否在多边形内部
#         item = self.scene().itemAt(pos, self.transform())
#         if isinstance(item, QGraphicsPolygonItem):
#             # 高亮显示多边形
#             item.setBrush(Qt.red)
#         else:
#             item = self.scene().items()
#             for i in item:
#                 if isinstance(i, QGraphicsPolygonItem):
#                     i.setBrush(Qt.NoBrush)

# if __name__ == "__main__":
#     app = QApplication(sys.argv)
#     radar_chart = RadarChart()
#     radar_chart.show()
#     sys.exit(app.exec())

import xml.etree.ElementTree as ET
from xml.dom.minidom import parse
def checkKeilAssert(uvprojx_path):
    """
    检查 USE_FULL_ASSERT 在Keil工程文件中的位置
    """
    # 加载XML文件
    tree = ET.parse(uvprojx_path)
    root = tree.getroot()

    # 获取多层节点的值
    value = root.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define').text
    if 'USE_FULL_ASSERT' not in value:
        new_value = value+',USE_FULL_ASSERT'

        # 修改多层节点的值
        root.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define').text = new_value

        # 保存修改后的XML文件
        tree.write(uvprojx_path)
        return False
    else:
        return True

uvprojx_path = r'D:\python_tool_list\source_data\编程规范\HK32F0xxA_Demo.uvprojx'    
checkKeilAssert(uvprojx_path)